import 'package:ati_package/core/extension/ati_widgets_extension.dart';
import 'package:ati_package/core/routes/app_routes.dart';
import 'package:ati_package/core/utils/ati_color.dart';
import 'package:ati_package/pages/common/ati_scaffold.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../../core/utils/ati_assets.dart';
import '../../../../core/utils/ati_enum.dart';
import '../../../../core/utils/ati_font.dart';
import '../../../common/widgets/ati_dialogs.dart';

class UserSettingView extends StatefulWidget {
  const UserSettingView({super.key});

  @override
  State<UserSettingView> createState() => _UserSettingViewState();
}

class _UserSettingViewState extends State<UserSettingView> {
  @override
  Widget build(BuildContext context) {
    return AtiScaffold(
      title: '隐私设置',
      body: ListView(
        children: [
          _buildItem(AtiSetModel.setCover, '加我好友时需要验证'),
          _buildItem(AtiSetModel.setCover, '允许别人搜索到我'),
          _buildItem(AtiSetModel.clearCache, '清楚缓存'),
          _buildItem(AtiSetModel.deleteAccount, '注销账号'),
          _buildFootbtn(),
        ],
      ),
    );
  }

  _buildItem(AtiSetModel setModel, String titleStr) {
    return Container(
      height: 46.r,
      margin: EdgeInsets.only(left: 16.r, top: 10.r, right: 16.r),
      padding: EdgeInsets.symmetric(horizontal: 16.r),

      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.r),
      ),
      child: Row(
        children: [
          Text(titleStr, style: TextStyle(fontSize: AtiFont.font12)),
          Spacer(),
          ...[
            if (setModel == AtiSetModel.setCover)
              SizedBox(
                width: 62.5.r, // 指定宽度
                height: 37.5.r, // 指定高度
                child: FittedBox(
                  fit: BoxFit.fill,
                  child: CupertinoSwitch(
                    value: true,
                    onChanged: (bool value) {},
                  ),
                ),
              ),

            SizedBox(width: 2.r),
            if ((setModel == AtiSetModel.clearCache) |
                (setModel == AtiSetModel.deleteAccount))
              Image.asset(
                width: 14.r,
                height: 14.r,
                AtiAssets.atiNextIcon,
                package: 'ati_package',
              ),
          ],
        ],
      ),
    ).addTapGesture(
      onTap: () {
        switch (setModel) {
          case AtiSetModel.setCover:
            {}
            break;
          case AtiSetModel.setDayRange:
            {}
            break;
          case AtiSetModel.clearCache:
            throw UnimplementedError();
          case AtiSetModel.deleteAccount:
            throw UnimplementedError();
        }
      },
    );
  }

  _buildFootbtn() {
    return Container(
      height: 40.r,
      alignment: Alignment.center,
      margin: EdgeInsets.only(left: 50.r, right: 50.r, top: 50.r),
      decoration: BoxDecoration(
        gradient: AtiColor.primaryGradient,
        borderRadius: BorderRadius.circular(20.r),
      ),
      child: Text(
        '退出登录',
        style: TextStyle(
          color: AtiColor.textHLColor1,
          fontSize: AtiFont.font14,
        ),
      ),
    ).addTapGesture(
      onTap: () {
        Get.toNamed(AtiAppRoutes.userLogin);
      },
    );
  }
}
